package com.augurit.common.system.util;

import com.augurit.common.system.web.org.form.OmUserPrivForm;

public class PrivilegeUtils {
	
	//节点外观设置
	public static final String CLS_ROLE = "icon-role";
	public static final String CLS_NO_RESULT = "icon-not-auth";
	public static final String UI_PROVIDER = "col";
	
	//节点ID分隔符
	public static final String NODE_SEPARATOR = "#";
	
	//已授权角色总节点
	public static final String AUTHED_NODE = "-1";
	//特别开通总节点
	public static final String PERMIT_NODE = "-21";
	//特别禁止总节点
	public static final String FORBID_NODE = "-20";
	//继承角色总节点
	public static final String INHERIT_NODE = "-3";
	
	//总节点类型
	public static final String TYPE_CONSTANT = "CONSTANT";
	//角色节点类型
	public static final String TYPE_ROLE = "ROLE";
	//功能节点类型
	public static final String TYPE_FUNC = "FUNC";
	
	
	private static OmUserPrivForm buildBlankNode(){
		OmUserPrivForm form = new OmUserPrivForm();
		form.setIconCls(PrivilegeUtils.CLS_NO_RESULT);
		form.setLeaf(true);
		return form;
	}
	
	public static OmUserPrivForm buildBlankAuthedNode(){
		OmUserPrivForm form = buildBlankNode();
		form.setName(changeFace("无任何已授权角色。"));
		return form;
	}
	
	public static OmUserPrivForm buildBlankForbidNode(){
		OmUserPrivForm form = buildBlankNode();
		form.setName(changeFace("无任何特别禁止功能。"));
		return form;
	}
	
	public static OmUserPrivForm buildBlankPermitNode(){
		OmUserPrivForm form = buildBlankNode();
		form.setName(changeFace("无任何特别开通功能。"));
		return form;
	}
	
	public static OmUserPrivForm buildBlankFuncNode(){
		OmUserPrivForm form = buildBlankNode();
		form.setName(changeFace("无任何关联功能。"));
		return form;
	}
	
	public static OmUserPrivForm buildBlankInheritNode(){
		OmUserPrivForm form = buildBlankNode();
		form.setName(changeFace("无任何继承角色。"));
		return form;
	}
	
	private static String changeFace(String text){
		return "<font color='gray'>" + text + "</font>";
	}
	
	/**
	 * 是否为总节点
	 * @return
	 */
	public static boolean isConstantNode(OmUserPrivForm node){
		if(node != null && node.getType() != null && node.getType().equals(TYPE_CONSTANT))
			return true;
		else
			return false;
	}
	
	/**
	 * 是否为已授权角色总节点
	 * @return
	 */
	public static boolean isAuthedNode(OmUserPrivForm node){
		if(node != null && node.getId() != null && node.getId().endsWith(
				PrivilegeUtils.NODE_SEPARATOR + PrivilegeUtils.AUTHED_NODE))
			return true;
		else
			return false;
	}
	
	/**
	 * 是否为特别开通总节点
	 * @return
	 */
	public static boolean isPermitNode(OmUserPrivForm node){
		if(node != null && node.getId() != null && node.getId().endsWith(
				PrivilegeUtils.NODE_SEPARATOR + PrivilegeUtils.PERMIT_NODE))
			return true;
		else
			return false;
	}
	
	/**
	 * 是否为特别禁止总节点
	 * @return
	 */
	public static boolean isForbidNode(OmUserPrivForm node){
		if(node != null && node.getId() != null && node.getId().endsWith(
				PrivilegeUtils.NODE_SEPARATOR + PrivilegeUtils.FORBID_NODE))
			return true;
		else
			return false;
	}
	
	/**
	 * 是否为继承角色总节点
	 * @return
	 */
	public static boolean isInheritNode(OmUserPrivForm node){
		if(node != null && node.getId() != null && node.getId().endsWith(
				PrivilegeUtils.NODE_SEPARATOR + PrivilegeUtils.INHERIT_NODE))
			return true;
		else
			return false;
	}
}
